package com.ww.springboot.boot.baseTest.date;

import java.time.*;
import java.time.format.DateTimeFormatter;

/**
 * 描述：
 *
 * @author 🧑 ‍wanwei
 * @since 2025-01-17 12:00
 */
public class TimeDemo {

    public static void main(String[] args) {
        LocalTime now = LocalTime.now();
        System.out.println("当前time:" + now);
        LocalTime min = LocalTime.MIN;
        System.out.println("最早time:" + min);
        LocalTime max = LocalTime.MAX;
        System.out.println("最晚time:" + max);


        LocalTime localTime1 = LocalTime.ofNanoOfDay(1);
        System.out.println("1纳秒:" + localTime1);
        LocalTime localTime10000 = LocalTime.ofNanoOfDay(10000);
        System.out.println("10000纳秒:" + localTime10000);
        LocalTime localTime100000000 = LocalTime.ofNanoOfDay(100000000);
        System.out.println("100000000纳秒:" + localTime100000000);
        LocalTime localTime1000000000 = LocalTime.ofNanoOfDay(1000000000);
        System.out.println("1000000000纳秒:" + localTime1000000000);
        System.out.println("一秒 == 一亿纳秒");
        //不能超过范围 并不能往前进位
        //LocalTime localTime1121 = LocalTime.of(1, 1, 1, 1000000000);
        //System.out.println("localTime:" + localTime1121);

        System.out.println("===========================================");
        LocalDate localDate = LocalDate.now();
        System.out.println("localDate:" + localDate);
        LocalDate minDate = LocalDate.MIN;
        System.out.println("minDate:" + minDate);
        LocalDate maxDate = LocalDate.MAX;
        System.out.println("maxDate:" + maxDate);
        //从1970-01-01开始算 增加天数
        LocalDate epochDay1 = LocalDate.ofEpochDay(1);
        System.out.println("epochDay:" + epochDay1);
        LocalDate epochDay10000 = LocalDate.ofEpochDay(10000);
        System.out.println("epochDay10000:" + epochDay10000);

        LocalDate yearDay365 = LocalDate.ofYearDay(2025, 365);
        System.out.println("yearDay365:" + yearDay365);
        //无法进位
//        LocalDate yearDay0 = LocalDate.ofYearDay(2025, 0);
//        System.out.println("yearDay365:" + yearDay0);
//        LocalDate yearDay366 = LocalDate.ofYearDay(2025, 366);
//        System.out.println("yearDay365:" + yearDay366);
        LocalDate parse = LocalDate.parse("2025-02-28");
        System.out.println("parse:" + parse);


        System.out.println("===========================================");
        LocalDateTime localDateTime = LocalDateTime.now();
        System.out.println("localDateTime:" + localDateTime);
        LocalDateTime localDateTime111111 = LocalDateTime.of(1, 1, 1, 1, 1, 1);
        System.out.println("localDateTime111111:" + localDateTime111111);
        LocalDateTime localDateTimeZoneDefault = LocalDateTime.now(ZoneId.systemDefault());
        System.out.println("localDateTimeZoneDefault:" + localDateTimeZoneDefault);
        LocalDateTime localDateTimeZoneShanghai = LocalDateTime.now(ZoneId.of("Asia/Shanghai"));
        System.out.println("localDateTimeZoneShanghai:" + localDateTimeZoneShanghai);
        LocalDateTime localDateTimeZoneNewYork = LocalDateTime.now(ZoneId.of("America/New_York"));
        System.out.println("localDateTimeZoneNewYork:" + localDateTimeZoneNewYork);
        //时间的某一瞬间
        Instant instant = Instant.now();
        LocalDateTime ofInstant = LocalDateTime.ofInstant(instant, ZoneId.of("Asia/Shanghai"));
        System.out.println("ofInstant:" + ofInstant);

        LocalDateTime dateTimeParse = LocalDateTime.parse("2025-11-11T11:11:11", DateTimeFormatter.ISO_LOCAL_DATE_TIME);
        System.out.println("dateTimeParse:" + dateTimeParse);

        Instant parseInstant = Instant.parse("2025-11-11T11:11:11.111Z");
        LocalDateTime parseInstantTime = LocalDateTime.ofInstant(parseInstant, ZoneId.of("Asia/Shanghai"));
        System.out.println("parseInstantTime:" + parseInstantTime);
    }


}
